import { AddLocationParam, EditLocationParam } from "@Tea/model"
import { AppTokenObj } from "../dao/AppToken"
import { LocationRepository } from "../repo/LocationRepository"

export class LocationCtx {
  private static inst: LocationCtx
  private locationRepo: LocationRepository = LocationRepository.getInstance()

  // 单例
  public static getInstance() {
    if (!LocationCtx.inst) {
      LocationCtx.inst = new LocationCtx()
    }

    return LocationCtx.inst
  }

  addLocation(params: AddLocationParam, customer: AppTokenObj['userId']) {
    return this.locationRepo.addLocation(params, customer)
  }

  setNotDetault(customer: AppTokenObj['userId']) {
    return this.locationRepo.setNotDetault(customer)
  }

  editLocation(params: EditLocationParam, customer: AppTokenObj['userId']) {
    return this.locationRepo.editLocation(params, customer)
  }

  deleteLocation(takeOverId: number, customer: AppTokenObj['userId']) {
    return this.locationRepo.deleteLocation(takeOverId, customer)
  }

  async locationList(customer: AppTokenObj['userId']) {
    return (await this.locationRepo.locationList(customer))[0]
  }
}